package com.firebird.app.kotlin.stock.trend.utils

import android.content.Context
import android.location.LocationManager
import android.net.ConnectivityManager


/**
 * Created by vslimit on 14-4-25.
 */
object NetworkUtil {
    fun isWifi(context: Context): Boolean {
        val cm = context
                .getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
        val info = cm.activeNetworkInfo
        return info != null && info.type == ConnectivityManager.TYPE_WIFI
    }

    fun isMobile(context: Context): Boolean {
        val cm = context
                .getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
        val info = cm.activeNetworkInfo
        return info != null && info.type == ConnectivityManager.TYPE_MOBILE
    }

    fun isNetwork(context: Context): Boolean {
        return isWifi(context) || isMobile(context)
    }

    fun isGps(context: Context): Boolean {
        val lm = context
                .getSystemService(Context.LOCATION_SERVICE) as LocationManager
        val accessibleProviders = lm.getProviders(true)
        return accessibleProviders != null && accessibleProviders.size > 0
    }
}
